#include "Node.h"

int Node_partition(Node* arr, int n);
int Node_quicksort(Node* arr, int n);

int Node_partition(Node* arr, int n){
  if (n<=0)
    return 0;
  int left =0;
  int right = n-1;
  Node pivot = arr[0];
  while (left != right){
    while (arr[right].get_num() <= pivot.get_num() && right > left)
      right--;
    while (arr[left].get_num() >= pivot.get_num() && right > left)
      left++;
    if (right > left){
      Node tmp = arr[left];
      arr[left]=arr[right];
      arr[right]=tmp;
      right--;
    }
  }
  arr[0] = arr[left];
  arr[left] = pivot;
  return left;
}

int Node_quicksort(Node* arr, int n){
  if (n>0){
    int p = Node_partition(arr,n);
    Node_quicksort(arr,p);
    Node_quicksort(arr+p+1,n-p-1);
  }
  return 0;
}
